package cc.shacocloud.luanniao.core.service.ai

import org.junit.jupiter.api.Test

/**
 *
 * @author 思追(shaco)
 */
class ExpandKtTest {

    @Test
    fun qaRegexText() {
        val text = """
        Q1：《毛泽东选集》第一卷包含哪些时期的内容？
        A1：《毛泽东选集》第一卷包含第一次国内革命战争时期和第二次国内革命战争时期的内容。
        Q2：《毛泽东选集》第一卷中提到了哪些著作？
        A2：《毛泽东选集》第一卷中提到了《中国社会各阶级的分析》《湖南农民运动考察报告》《中国的红色政权为什么能够存在？》《井冈山的斗争》《关于纠正党内的错误思想》《星星之火，可以燎原》《反对本本主义》《必须注意经济工作》《怎样分析农村阶级》《我们的经济政策》《关心群众》等著作。
        Q3: What periods are included in the first volume of Selected Works of Mao Zedong?
        A3: The first volume of the Selected Works of Mao Zedong contains content from the First Civil Revolutionary War period and the Second Civil Revolutionary War period.
        Q4: What writings are mentioned in the first volume of Selected Works of Mao Zedong?
        A4: The first volume of the Selected Works of Mao Zedong mentions The Analysis of the Various Classes in Chinese Society, The Report on the Examination of the Peasant Movement in Hunan, Why the Red Regime in China Can Exist? The Struggle at Jinggangshan”, ‘On Correcting the Wrong Ideas in the Party’, ‘A Star's Fire Can Start a Prairie Fire’, ‘Against Capitalism’, ‘Attention Must Be Paid to Economic Work’, ‘How to Analyze the Rural Classes’, ‘Our Economic Policies’, and ‘Caring for the Masses’, among other writings.
    """.trimIndent()

        val list = QA_REGEX.findAll(text)
            .mapNotNull {
                val question = it.groups[1]?.value
                var answer = it.groups[2]?.value?.trim()
                answer = if (answer.isNullOrBlank()) null else LINE_BREAKS_BLANKS_REGEX.replace(answer, "\n")

                if (question.isNullOrBlank() || answer.isNullOrBlank()) {
                    null
                } else {
                    QAPair(question, answer)
                }
            }
            .toList()

        list.forEach { println(it) }
    }


}